$(function() {
	$(document).on("click", '.adregister', function(e) {
        var phone = $('.phone').val();
		var mail = $('.mail').val();
		var trade = $('#trade').attr('sid');
		var origin = $('.adregister').attr('origin');
		
		var verify = $('.verify').val();
		if(phone==''||!phone||phone=='您的手机号码')
		{
			tips('请填写电话号码！','phone');return;
		}
		if(!checkPhone('.phone')) return false;
		if(!checkMail('.mail')) return false;
		if(!checkTrade('.trade')) return false;
		if(!checkVerify()) return false;
		//ajax验证
		$.ajax({
				url: "/User/Login/adRegister.html",
				data: "mobile="+phone+"&mail="+mail+"&trade="+trade+"&verify="+verify+"&origin="+origin,
				type: "post",
				dataType: "json",
				success: function(ret) 
				{
					if(ret.status==0)
					{
						
						return false;
					}
					if(ret.status==1)
					{
						
						//注册成功 跳转到发验证码页面
						window.location.href = HAOWJ + "/userlogin/regsuccess.htm?type=verify&mobile="+phone;
						return;
					}
				}
		});
    })
	$(document).on("click", '.reg_sel li', function(e) {
       	checkTrade('.trade');
    })
});
function tips(con,tipid)
{
	$("#"+tipid).show();
	layer.tips(con, "#"+tipid,  {
		style: ['background-color:#e62727; color:#fff;right:103px;', '#e62727'],
		maxWidth:150,
		more:1,
		guide:0,
		time:0,
		
	});
}
function tipsclose(obj)
{
	$('#'+obj).hide();
	$('.xubox_layer').remove();
}
//jquery验证手机号码
function checkPhone(obj) 
{
 
    var flag = $(obj).val().match(/^1[3|4|5|8][0-9]\d{4,8}$/);
    if (!flag || $(obj).val().length != 11) 
	{
		tips('无效的手机号码！','phone');
        return false;
    }
	var ret =false;
    //ajax验证
	 $.ajax({
            url: "/User/Login/ajaxCheckMobile.html",
            data: "mobile="+$(obj).val(),
            type: "post",
            dataType: "json",
            success: function(ret) 
			{
                if(ret.status==0)
				{
					tips(ret.info,'phone');
					var ret = true;
				}
            }
    });
	
	if(ret==true) return false;
	tipsclose('phone');
    return true;
}
//jquery验证邮箱
function checkMail(obj) 
{
    if ($(obj).val() == "" || $(obj).val() == '您的邮箱') 
	{
      	tips('请填写邮箱地址！','mail');
        return false;
       
    }
    var flag = $(obj).val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
    if (!flag) {
        tips('无效的邮箱地址！','mail');
        
        return false;
    }
	tipsclose('mail');
    return true;
}
//检查行业
function checkTrade(obj)
{
	var result = $('.trade').attr('sid');
	
	if(result==0)
	{
		layer.tips('请填写您的行业！', "#trade",  {
			style: ['background-color:#e62727; color:#fff;left:60px;', '#e62727'],
			maxWidth:150,
			more:1,
			guide:0,
			time:0,
		
		});
        return false;
	}
	$('.xubox_layer').remove();
    return true;
}
//检查验证码
function checkVerify()
{
	var verify	= $('.verify').val();
	if(verify==''||verify=='输入验证码')
	{
		layer.tips('请填写验证码！', ".verify",  {
			style: ['background-color:#e62727; color:#fff;left:5px;', '#e62727'],
			maxWidth:150,
			more:1,
			guide:1,
			time:0,
		
		});
		return false;
	}
	var rets =false;
	//ajax验证
	 $.ajax({
            url: "/User/Login/ajaxCheckVerify.html",
            data: "verify="+verify,
            type: "post",
            dataType: "json",
            success: function(ret) 
			{
                if(ret.status==0)
				{
					layer.tips('验证码错误！', ".verify",  {
						style: ['background-color:#e62727; color:#fff;left:5px;', '#e62727'],
						maxWidth:150,
						more:1,
						guide:1,
						time:0,
					
					});
					var rets = true;
					
				}
            }
    });
	if(rets==true) return false;
	$('.xubox_layer').remove();
    return true;
}













